package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;


import java.util.*;

/**
 * 集合 相关模版引擎测试
 *
 * @Author mr.lin
 * @Date 2025/1/24 17:07
 */
@Controller
public class CollectionController {

    @GetMapping("/collection")
    public String list(Model model) {
        //list 相关
        List<Student> list = new ArrayList<>();
        Student stu1 = new Student("张三", 18, new Date(), 18f);
        list.add(stu1);
        Student stu2 = new Student("李四", 19, new Date(), 19f);
        list.add(stu2);
        model.addAttribute("list", list);

        //map相关
        Map<String, Student> map = new HashMap<>();
        map.put("stu1", stu1);
        map.put("stu2", stu2);
        model.addAttribute("stuMap", map);
        return "02-list";
    }
}
